package com.example.appmutlithread;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

public class Downdload extends AsyncTask<String,Integer, Boolean> {
	TextView textprog;
	ProgressBar progressbar;
	final int totalProgressTime = 100;

	public Downdload(TextView textprog, ProgressBar progressbar) {
		super();
		this.textprog = textprog;
		this.progressbar = progressbar;
	}

	
	public void progresElm(){
		int count=0;
		while(count<totalProgressTime){
			try {
				Thread.sleep(200);
				count +=5;
				publishProgress(count);
			} catch (Exception e) {
				
			}	
		
		
		}
		
	}
	
	
	@Override
	protected Boolean doInBackground(String... params) {
		Log.i("trace ","do in back");
		Log.i("trace ","url de dl : "+params[0]);
		Log.i("trace ","chemin de sauvegarde : "+params[1]);
		for(int i=1; i<=10; i++){
			publishProgress(10);
			try {
				Thread.sleep(500);
			} catch (Exception e) {
				
			}
				
		}
			return true;
	}
    
	@Override
	protected void onPreExecute() {
		textprog.setText(0+"%");
		
		Log.i("trace ","pre");
	}
	
	@Override
	protected void onPostExecute(Boolean result) {
		textprog.setText(100+"%");
		progressbar.setProgress(100);
		Log.i("trace ","post");
	}
	@Override
	protected void onProgressUpdate(Integer... values) {
        textprog.setText(values[0]+"%");
        progressbar.setProgress(values[0]);
		Log.i("trace ","progress : " +values[0]);
	}
}
